package indi.zhifa.study2024.class002.busy.generalTest.business.report.consign.entity.response;

import indi.zhifa.study2024.class002.busy.generalTest.business.report.consign.entity.mapperOut.ConsignMapperOut;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;

import java.math.BigDecimal;
import java.math.RoundingMode;
import java.text.DecimalFormat;

@Data
public abstract class BaseConsignReportResponse {
    @Schema(title = "总成本")
    Long cost;
    @Schema(title = "总金额")
    Long amount;
    @Schema(title = "总利润")
    Long profit;
    @Schema(title = "利润率")
    Double profitRatio;

    @Schema(title = "销售成本")
    Long saleCost;
    @Schema(title = "销售毛利")
    Long saleAmount;

    @Schema(title = "退货成本")
    Long returnCost;
    @Schema(title = "退货毛利")
    Long returnAmount;


    public void initWithMapperOut(ConsignMapperOut pConsignMapperOut){
        cost = pConsignMapperOut.getCost();
        amount = pConsignMapperOut.getAmount();
        profit = pConsignMapperOut.getProfit();
        profitRatio = pConsignMapperOut.getProfitRatio();

        saleCost = pConsignMapperOut.getSaleCost();
        saleAmount = pConsignMapperOut.getSaleAmount();

        returnCost = pConsignMapperOut.getReturnCost();
        returnAmount = pConsignMapperOut.getReturnAmount();

        onInitWithMapperOut(pConsignMapperOut);
    }

    abstract protected void onInitWithMapperOut(ConsignMapperOut pConsignMapperOut);


    String costDesc;
    String amountDesc;
    String profitDesc;
    String profitRatioDesc;
    String saleCostDesc;
    String saleAmountDesc;
    String returnCostDesc;
    String returnAmountDesc;


    public void cal(){
        costDesc = BigDecimal.valueOf(cost).divide(BigDecimal.valueOf(100),2, RoundingMode.HALF_UP).toString()+"元";
        amountDesc = BigDecimal.valueOf(amount).divide(BigDecimal.valueOf(100),2, RoundingMode.HALF_UP).toString()+"元";
        profitDesc = BigDecimal.valueOf(profit).divide(BigDecimal.valueOf(100),2, RoundingMode.HALF_UP).toString()+"元";
        DecimalFormat df = new DecimalFormat("#.00");
        profitRatioDesc = df.format(profitRatio*100)+"%";
        saleCostDesc = BigDecimal.valueOf(saleCost).divide(BigDecimal.valueOf(100),2, RoundingMode.HALF_UP).toString()+"元";
        saleAmountDesc = BigDecimal.valueOf(saleAmount).divide(BigDecimal.valueOf(100),2, RoundingMode.HALF_UP).toString()+"元";
        returnCostDesc = BigDecimal.valueOf(returnCost).divide(BigDecimal.valueOf(100),2, RoundingMode.HALF_UP).toString()+"元";
        returnAmountDesc = BigDecimal.valueOf(returnAmount).divide(BigDecimal.valueOf(100),2, RoundingMode.HALF_UP).toString()+"元";
    }


}
